import java.io.FileWriter;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.SQLException;

public class CreateIni {

    public static void main(String[] args) throws IOException, InterruptedException, SQLException {
        int[] subdomain = new int[2];
        int count = 0;
        for(int i=0;i<=1000;i++){
            URL url = new URL("http://app"+i+".knowledge0603.fun:8011/");
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            int state = con.getResponseCode();
            if (state != 200) {
                subdomain[count] = i;
                count = count+1;
            }
            if(count==2){
                break;
            }
        }
        writeFile(subdomain);
    }
    public static void writeFile(int[] subdomain ) throws IOException {
        String fileName= "frpc.ini";

        FileWriter writer=new FileWriter(fileName);
        writer.write( "[common]\n");
        writer.write("server_addr = 120.53.240.110\n");
        writer.write("server_port = 7000\n");
        writer.write("auth_token = 123456\n");
        writer.write("vhost_http_port = 8011\n");

        writer.write("[web_wordpress_"+subdomain[0]+"]\n");
        writer.write("type = http \n");
        writer.write("local_ip = 127.0.0.1 \n");
        writer.write("local_port = 8011 \n");
        writer.write("subdomain = app"+subdomain[0]+"\n");

        writer.write("[web_search_"+subdomain[1]+"]\n");
        writer.write("type = http \n");
        writer.write("local_ip = 127.0.0.1 \n");
        writer.write("local_port = 9093 \n");
        writer.write("subdomain = app"+subdomain[1]+"\n");
        writer.close();
    }
}
